package com.yq.ylmall.acl.controller;


import com.yq.ylmall.acl.service.MenuService;
import com.yq.ylmall.model.acl.Menu;
import com.yq.ylmall.result.Result;
import com.yq.ylmall.result.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author cherry
 * @since 2024-05-30
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping(value="/admin/system/menu")
public class MenuController{
    @Autowired
    private MenuService sysMenuService;

    @ApiOperation(value = "递归查询菜单")
    @GetMapping("/findNodes")
    public Result<List<Menu>> findNodes() {
        List<Menu> list = sysMenuService.findNodes();
        return Result.build(list , ResultCode.SUCCESS) ;
    }

    @ApiOperation(value = "添加菜单")
    @PostMapping("/save")
    public Result save(@RequestBody Menu menu) {
        sysMenuService.saveMenu(menu);
        return Result.build(null , ResultCode.SUCCESS) ;
    }

    @ApiOperation(value = "添加菜单")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Menu menu) {
        sysMenuService.updateById(menu);
        return Result.build(null , ResultCode.SUCCESS) ;
    }

    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable Long id) {
        sysMenuService.removeByIdMenu(id);
        return Result.build(null , ResultCode.SUCCESS) ;
    }
}
